import {Injectable} from '@angular/core';

import {ToolsService} from "@shared/service/tools/tools.service";
import {Observable} from "rxjs";

import {Response} from "@angular/http";
import {HttpService} from "@core/http/http.service";
import * as API from "@api/index";
import {ActivatedRoute} from "@angular/router";
import {
  CommonPageVo, IpAuthCenterVO, IpAuthRoleRespVO, RecommendServiceMenuResqVo, SNSResult,
  UserDeliveryAddressVO
} from "@interface/index";



@Injectable()
export class MineService {
  private saveClassTag = 'LaunchClass';

  constructor(public httpService: HttpService,
              public toolsService: ToolsService) {

  }

  fetchRouteData(route: ActivatedRoute) {
    return route.data;
  }

  fetchUserPorfile(route: ActivatedRoute) {
    return this.fetchRouteData(route)
      .map(data => data.profile)
      .filter((item) => item.result === '0')
      .map(res => res.data);
  }

   // 退出登录
  goLoginOut() {
    return this.httpService.post(API.Login_Out, '').map((res: Response) => res.json());
  }

   // 查询用户信息
  getUserInfo(userId: string) {
    const url = API.USER_INFO + '?userId=' + userId;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

   //  编辑个人信息
  UserInfoUpdate(data) {

     //  let cwh = $.param(opt);
    const url = API.USER_INFO_UPDATE_URL;
    return this.httpService.putUrlencode(url, data).map((res: Response) => res.json());
  };

   //  上传头像
  updateAvatar(file) {
    const url = API.AVATAR_URL;
    return this.httpService.upload(url, file).map((res: Response) => res.json());
  }

   // 我的评论
  getMyComments(params) {
    const url = API.COMMENT_ME_URL + '?' + this.toolsService.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  };
  // 获取我的收藏列表
  getUserFavoriteList(data) {
    const url = API.GET_USER_FAVORITE_LIST + "?" + this.toolsService.params(data);
    return this.httpService.get(url).map((res: Response) => res.json());
  }
   // @Me
  getAtMe(params) {
    const url = API.AT_ME_URL + '?' + this.toolsService.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  };

   // 我的点赞
  getDiggMe(params) {
    const url = API.DIGG_ME_URL + '?' + this.toolsService.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  };

   // 获取地区数据
  getArea() {
    const url = API.AREA_URL + '?langType=zh_CN';
    return this.httpService.get(url).map((res: Response) => res.json());
  };

   // 获取我的咨询
  getMyInfo(params) {
    const url = `${API.ARTICLE_LIST}?${this.toolsService.param(params)}`;
    return this.httpService.get(url).map((res: Response) => res.json());
  };

   // 获取我的点赞
  getMyDigg(params) {
    const url = API.FEED_DIGG_URL + `?` + this.toolsService.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  };

   // 查询用户地址信息
  getUserAddress(userId: string): Observable<SNSResult<CommonPageVo<UserDeliveryAddressVO>>> {
    const url = API.USER_ADDRESS_URL + '?userId=' + userId;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

   //  新增地址
  postNewAdress(data): Observable<SNSResult<number>> {
    const url = API.USER_ADDRESS_URL;
    return this.httpService.postUrlencode(url, data).map((res: Response) => res.json());
  }


   //  getOrdersDetail(orderId:number):Observable<SNSResult<OrderDetailRespVO>>{
   //    let url = API.ORDER_INFO_URL+'?orderNumber='+orderId;
   //    return this.httpService.get(url).map((res:Response) => res.json());
   //  }


   // 获取钱包明细（账单）
  getWalletBill(params) {
    const url = API.WALLET_DETAIL + '?' + this.toolsService.param(params);
    return this.httpService.get(url).map((res: Response) => res.json());
  }

   // 获取钱包信息
  getWalletInfo() {
    const url = API.WALLET_INFO;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

   // 获取IP被授予的角色
  getMoreIp() {
    const url = API.USER_MORE_IP;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

   // 获取我的工多功能
  getMoreFun() {
    const url = API.USER_MORE_FUN;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

   // 获取我的信息
  getMineInfo() {
    const url = API.GET_USER_INFO;
    return this.httpService.get(url).map((res: Response) => res.json());
  }

  // 获取用户认证中心
  getAuthCenter(): Observable<SNSResult<IpAuthCenterVO>> {
    const url = API.AUTH_CENTER;
    return this.httpService.get(url).map((res: Response) => res.json());
  }
  // 获取推荐服务菜单列表
  getServiceMenu(): Observable<SNSResult<RecommendServiceMenuResqVo>> {
    const url = API.GET_SERVICE_MENU;
    return this.httpService.get(url).map((res: Response) => res.json());
  }
  // 获取角色授权信息
  getAuthRoleResp(orgUserId): Observable<SNSResult<IpAuthRoleRespVO>> {
    const url = API.GET_GRANT_DETAIL + "?orgUserId=" + orgUserId;
    return this.httpService.get(url).map((res: Response) => res.json());
  }
}


